package com.kjsdfgk.hjmdsf.ftlive.mvp.model;

import android.app.Application;
import android.util.Base64;

import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;

import com.jess.arms.di.scope.FragmentScope;

import javax.inject.Inject;

import com.kjsdfgk.hjmdsf.app.api.service.CommonService;
import com.kjsdfgk.hjmdsf.app.entity.AccountJson;
import com.kjsdfgk.hjmdsf.app.entity.RegJson;
import com.kjsdfgk.hjmdsf.ftlive.mvp.contract.LiveV3FtContract;
import com.kjsdfgk.hjmdsf.live.mvp.bean.ResultLive;
import com.kjsdfgk.hjmdsf.live.mvp.bean.VersionEntity;


import cn.leancloud.codec.MD5;
import io.reactivex.Observable;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 04/30/2020 17:54
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
@FragmentScope
public class LiveV3FtModel extends BaseModel implements LiveV3FtContract.Model {
    @Inject
    Gson mGson;
    @Inject
    Application mApplication;

    @Inject
    public LiveV3FtModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }



    @Override
    public Observable<ResultLive> getPingTaiJson() {
//        String url = "http://api.hclyz.com:81/mf/json.txt";api.hclyz.com:81/mf/json.txt
//        String strBase64 = Base64.encodeToString(url.getBytes(), Base64.DEFAULT);
        String url = "aHR0cDovL2FwaS5oY2x5ei5jb206ODEvbWYvanNvbi50eHQ=";

//base64解码
        url = new String(Base64.decode(url.getBytes(), Base64.DEFAULT));

        Observable<ResultLive> result = mRepositoryManager.obtainRetrofitService(CommonService.class)
                .getPingTaiInfo( url  );
        return result;
    }

    @Override
    public Observable<VersionEntity> checkVersion() {
        Observable<VersionEntity> result = mRepositoryManager.obtainRetrofitService(CommonService.class)
                .checkVersion(  );
        return result;
    }

    @Override
    public Observable<RegJson> userReg(String user , String password) {
        int inv = 34;
        Observable<RegJson> result = mRepositoryManager.obtainRetrofitService(CommonService.class)
                .userReg( user ,password , user, inv , System.currentTimeMillis());
        return result;
    }

    @Override
    public Observable<AccountJson> userLogon(String account, String password) {

        Observable<AccountJson> result = mRepositoryManager.obtainRetrofitService(CommonService.class)
                .userLogonApi( account ,password , account , System.currentTimeMillis());
        return result;
    }
}